/*
	Copyright e Professional 2002
	Author Manz
	Eprofessional Menu
	Release 1.0.30072002
		- Developer for Hutchison Project.
		- Support main menu, favorite menu and toolbar menu.
		- Support fade effect, Microsoft standard.
		- Design on resolution 1024*768
		- Each choice can change to new location or invoke defined function javaScript.
		- All contents store in javaScript Array variable.
*/

//	Default up one level value
var upOneLevel = new Array(UP_ONE_LEVEL_IMG, 'Up one level', 'Back to the previous menu.', '') ;

//	Main Menu data.
//	0.	Menu name
//	1.	Menu description
//		For the example new Array('Administrator Menu', 'All program(s) require Administrator privilege.') ;
var menuDesc ;
/*
	Defined menu content(s) in Array variable with format as follow.
			+-------------------+----------------------------------------------------------------------------------------------+
			|		index			|													Description														|
			+-------------------+----------------------------------------------------------------------------------------------+
			|			0				|	picture, icons image																						|
			|			1				|	menu label																										|
			|			2				|	menu description, ex. image alt.																	|
			|			3				|	target location (html, jsp), defined function javaScript	or  submenu		|
			+-------------------+----------------------------------------------------------------------------------------------+
*/	
var allMenuContent  ;

//	menuManager variables
var menuContent ;
var originalContent = new Array() ;
var menuLevel = 0 ;
var doFadeTimer, unFadeTimer, offMenuTimer ;
var currentMenu, oldMenu ;

//var subMenu = false ;

function whenMouseOverMenu(obj) {
	clearTimeout(offMenuTimer) ;
	setText(menuContent[parseInt(obj.id.substring(6))][2]) ;
	currentMenu = obj ;

	if (currentMenu != oldMenu) {	// new menu is actived.
		if (oldMenu != null) {
			unFade(50) ;
		}
		oldMenu = currentMenu != null ? currentMenu : oldMenu ;
	}
	doFade(currentMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity) ;			
}

function whenMouseOut(obj) {
	setText("") ;
	if (obj != oldMenu) {
		if(oldMenu != null) {
			offMenuTimer = setTimeout("unFade(oldMenu.filters(\"DXImageTransform.Microsoft.Alpha\").Opacity)", 100) ;
		}
	}
}

function whenMouseClickMenu(obj) {
	var temp = null ;
	temp = menuContent[parseInt(obj.id.substring(6))][3] ;
	if (temp[0] != null) {	//	Draw new menu.
		if(menuContent[parseInt(obj.id.substring(6))][0].indexOf("upOneLevel") != -1) {	// Up to previous level menu.
			menuContent = null ;
			menuContent = originalContent[--menuLevel] ;	//  Decrease menuLevel and pop menu from stack.
			originalContent[menuLevel + 1] = null ;	//	Clear ole value.
			upOneLevel[3] = new Array('', '', '', '') ;
		} else {	// Go to next level menu.
			originalContent[menuLevel++] = menuContent ;	//	Push current menu into stack and increase menuLevel.
			upOneLevel[3] = new Array('', '', '', '') ;
			menuContent = null ;
			menuContent = temp ;
			if (temp[temp.length - 1][0].indexOf("upOneLevel") == -1)
				menuContent[temp.length] = upOneLevel ;
		}
		currentMenu = null ;
		oldMenu = null ;
		drawMenu() ;
	} else {
//		whereGo.innerText = "Hey " + temp + " I want to go " + menuContent[parseInt(obj.id.substring(6))][3] ;
		parent.parentCurrentContent = new Array() ;
		parent.parentOriginalMenu = new Array() ;
		parent.parentCurrentContent = menuContent ;
		parent.parentOriginalMenu = originalContent ;
		parent.parentMenuLevel = menuLevel ; 
		
				programLayer.style.visibility='hidden';
				processingLayer.style.visibility='visible';
                                
                parent.backBtn.style.display = 'none';			 // *** dho modified, Hiding Back button.
                parent.homeBtn.style.display = 'none'; 		 // *** dho modified, Hiding Home button.
                
		location.href = menuContent[parseInt(obj.id.substring(6))][3] ;
	}
}

function doFade(iOpacity) {
	if (iOpacity< 91) {
		iOpacity += 10 ;
		if (currentMenu != null)
			currentMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity = iOpacity ;
		doFadeTimer = setTimeout("doFade("+ iOpacity +")", 1) ;
	} else {
		clearTimeout(doFadeTimer) ;
	}
}

function unFade(iOpacity) {
	if (iOpacity > 41) {
		iOpacity -= 10 ;
		if (oldMenu != null)
			oldMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity = iOpacity ;
		unFadeTimer = setTimeout("unFade("+ iOpacity +")", 1) ;
	} else {
		oldMenu = currentMenu != null ? currentMenu : oldMenu ;
		clearTimeout(unFadeTimer) ;
	}
}

/*
	Out of  all menus.
*/
function offMenu() {
	setText("") ;
	if (oldMenu != null) {
		offMenuTimer = setTimeout("unFade(oldMenu.filters(\"DXImageTransform.Microsoft.Alpha\").Opacity)", 300) ;
	}
}

function setText(txt) {
	menuHint.filters[0].apply() ;
	menuHint.innerText = txt ;
	menuHint.filters[0].play() ;
}

function drawMenu() {
    var sourceMenu = "<TABLE WIDTH=\"98%\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" STYLE=\"border: 0px\" onMouseOut=\"offMenu()\">" ;
    var dispBack = 'inline';

  parent.checkHomeButton();
  
  for (i = 0 ; i < menuContent.length ; i++) {

		sourceMenu += "<TR>" ;
			sourceMenu += "<TD>" ;

// *** dho modified        
        //alert(' menuContent length:> '+menuContent[menuLevel][0]);
				if (menuContent[i][0].indexOf("upOneLevel") != -1) {	
					parent.backBtn.style.display = 'inline';
					parent.backBtn.name = i;
					dispBack = 'none';					
				} else {
					parent.backBtn.style.display = 'none';
					dispBack = 'inline';
				}
                          
// *** dho modified

//				sourceMenu += "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\" id=imgObj"+i+" CLASS=\"menuIcon\" onMouseOver=\"whenMouseOverMenu(this)\" onMouseOut=\"whenMouseOut(this)\" onClick=\"whenMouseClickMenu(this)\" onContextMenu=\"return drawContextMenu(this)\">" ;
			// *** dho modified
				sourceMenu += "<TABLE ALIGN=\"right\" WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\" id=imgObj"+i+" CLASS=\"menuIcon\" onMouseOver=\"whenMouseOverMenu(this)\" onMouseOut=\"whenMouseOut(this)\" onClick=\"whenMouseClickMenu(this)\"style=\"display:"+dispBack+"\">" ;
				sourceMenu += "<TR STYLE=\"border: 5px\">" ;
//					sourceMenu += "<TD id=imgObjText ALIGN=\"right\" STYLE=\"border: 0px\"></TD>" ;
					sourceMenu += "<TD id=\"imgObjText\" ALIGN=\"right\" STYLE=\"border: 0px\"><font class=\"menuItemStyle\">&nbsp;"+menuContent[i][1]+"</font></TD>" ;

					sourceMenu += "<TD WIDTH=\"32px\" STYLE=\"border: 0px\"><IMG src=\""+menuContent[i][0]+"\" align=\"left\" id=\"oImg\" STYLE=\"border: 0px\"></TD>" ;
				sourceMenu += "</TR>" ;
				sourceMenu += "</TABLE>" ;
			
			sourceMenu += "</TD>" ;
		sourceMenu += "</TR>" ;
}
	sourceMenu += "</TABLE>" ;
     
menuPanel.filters[0].apply() ;
menuPanel.innerHTML = sourceMenu ;
menuPanel.filters[0].play() ;
}

/*
	These handle all Context Menu on this page.
*/
var contextFadeTimer, contextUnFadeTimer, offContextTimer ;

function drawContextMenu(obj) {
	clearTimeout(offMenuTimer) ;
	clearTimeout(offContextTimer) ;
	var tHtml ;

	contextMenu.style.left = event.x - 5 ;
	contextMenu.style.top = event.y - 5 ;
	if(obj.id.indexOf("imgObj") < 0) {	// Context on Favorite Bar.
		tHtml = "&nbsp;Remove <SPAN STYLE=\"color: darkred; font-weight: bold\">"+(favoriteContent[parseInt(obj.id.substring(6))][1] != null ? favoriteContent[parseInt(obj.id.substring(6))][1] : obj.innerText)+"</SPAN> from Favorite Bar." ;
		contextMenu.style.top = event.y - 20 ;
	} else {	//	Context on menu panel.
		if(menuContent[parseInt(currentMenu.id.substring(6))][3][0] != null) {	// Found Sub menu.
			tHtml = "&nbsp;<SPAN STYLE=\"color: darkred; font-weight: bold\">Cannot</SPAN> add depended menu ( "+obj.innerText+" ) to Favortite Bar." ;
		} else {
			tHtml = "&nbsp;Add <SPAN STYLE=\"color: darkred; font-weight: bold\">"+obj.innerText+"</SPAN> to Favortite Bar." ;
		}
	}

	contextText.innerHTML = tHtml ;
	contextMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity = 0 ;
	contextMenu.style.display = "block" ;
	contextFader() ;

	return false ;
}

function whenMouseOnContext() {
	clearTimeout(offMenuTimer) ;
	clearTimeout(offContextTimer) ;
}

function whenMouseOutContext() {
	offContextTimer = setTimeout("contextUnFade()", 100) ;
}

function whenMouseClickContext() {
	if(contextMenu.innerText.toLowerCase().indexOf("add") > 0) {	// Found Add into Favorite Bar method.
		if(currentMenu != null)
			whereGo.innerText = "Add " + currentMenu.innerText + " into Favorite Bar." ;
		else
			whereGo.innerText = "Add into Favorite Bar." ;
	} else {	// Found remove from Favorite Bar method.
		whereGo.innerText = "Remove "+(favoriteContent[parseInt(currentMenu.id.substring(6))][1] != null ? favoriteContent[parseInt(currentMenu.id.substring(6))][1] : currentMenu.innerText)+" from Favorite Bar." ;
	}
}

function contextFader() {
	if (contextMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity < 99) {
		contextMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity += 2 ;
		contextFadeTimer = setTimeout("contextFader()", 1) ;
	} else {
		clearTimeout(contextFadeTimer) ;
	}
}

function contextUnFade() {
	clearTimeout(contextFadeTimer) ;
	clearTimeout(offContextTimer) ;
	if (contextMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity > 21) {
		contextMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity -= 10 ;
		contextUnFadeTimer = setTimeout("contextUnFade()", 1) ;
	} else {
		clearTimeout(contextUnFadeTimer) ;
		contextMenu.style.display = "none" ;
	}
}

/*
	These handle all Favorite Bar.
	event onMouseOver, onMouseOut, onMouseClick use same as menu.

	Defined favorite menu content(s) in Array variable with format as follow.
			+-------------------+----------------------------------------------------------------------------------------------+
			|		index			|													Description														|
			+-------------------+----------------------------------------------------------------------------------------------+
			|			0				|	picture, icons image																						|
			|			1				|	menu label																										|
			|			2				|	menu description, ex. image alt.																	|
			|			3				|	target location (html, jsp)																				|
			+-------------------+----------------------------------------------------------------------------------------------+
*/

var favoriteContent ;

function drawFavorite() {
	iHtml = "<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" onMouseOut=\"offMenu()\"><TR ID=favoritePanel>" ;
	for(i = 0 ; i < favoriteContent.length ; i++) {
		iHtml += "<TD STYLE=\"text-align: center; font-size: 8px\">" ;
			iHtml += "<TABLE ID=favObj"+i+" BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\" STYLE=\"FILTER: progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=20)\"  onMouseOver=\"whenMouseOverFavorite(this)\" onMouseOut=\"whenMouseOut(this)\" onClick=\"onMouseClickFavorite(this)\" onContextMenu=\"return drawContextMenu(this)\">" ;
			iHtml += "<TR>" ;
				iHtml += "<TD STYLE=\"text-align: center; font-weight: bold; font-size: 8px; color: #333333\">"+(favoriteContent[i][1].length > 6 ? favoriteContent[i][1].substring(0, 6)+"..." : favoriteContent[i][1])+"</TD>" ;
			iHtml +="</TR>" ;
			iHtml += "<TR>" ;
				iHtml += "<TD STYLE=\"text-align: center; font-size: 8px\"><IMG src=\""+favoriteContent[i][0]+"\" WIDTH=\"22px\" HEIGHT=\"22px\" STYLE=\"border: 0px\"></TD>" ;
			iHtml += "</TR>" ;
			iHtml += "</TABLE>" ;
		iHtml += "</TD>" ;		
	}
	iHtml += "</TR></TABLE>" ;
	favoriteBar.innerHTML = iHtml ;
}

function whenMouseOverFavorite(obj) {
	clearTimeout(offMenuTimer) ;
	setText(favoriteContent[parseInt(obj.id.substring(6))][2]) ;
	currentMenu = obj ;

	if (currentMenu != oldMenu) {	// new menu is actived.
		if (oldMenu != null) {
			unFade(40) ;
		}
		oldMenu = currentMenu != null ? currentMenu : oldMenu ;
	}
	doFade(currentMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity) ;			
}

function onMouseClickFavorite(obj) {
	whereGo.innerText = "From Favorite!!! Go go go " + favoriteContent[parseInt(obj.id.substring(6))][3] ;
}

/*
	Use all these for toolbar.

	Defined toolbar menu content(s) in Array variable with format as follow.
			+-------------------+----------------------------------------------------------------------------------------------+
			|		index			|													Description														|
			+-------------------+----------------------------------------------------------------------------------------------+
			|			0				|	picture, icons image																						|
			|			1				|	menu label																										|
			|			2				|	menu description, ex. image alt.																	|
			|			3				|	target location (html, jsp) or defined function javaScript							|
			+-------------------+----------------------------------------------------------------------------------------------+
*/
var toolbarContent ;
var	toolbarMenuTimer ;

function drawToolbar() {
	IMAGE_ICON_WIDTH = 24 ;		//	Image icon HEIGHT, WIDTH properties.
	TOOLBAR_TOP = 20 ;				//	Toolbar y-position.
	TOOLBAR_LEFT = 650 ;			//	Toolbar x-position.

	tHtml = "<TABLE STYLE=\"cursor: hand\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" onMouseOut=\"offMenu()\"><TR ID=toolbarPanel>" ;
	for(i = 0 ; i < toolbarContent[0].length ; i++) {
		tHtml += "<TD STYLE=\"text-align: center; font-size: 8px\">" ;
			tHtml += "<TABLE ID=tooObj"+i+" BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\" STYLE=\"FILTER: progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=20)\"  onMouseOver=\"whenMouseOverToolbar(this)\" onMouseOut=\"whenMouseOut(this)\" onClick=\""+(toolbarContent[0][i][3].indexOf("call") >= 0 ? toolbarContent[0][i][3].substring(5) : "onMouseClickToolbar('"+toolbarContent[0][i][3]+"')")+"\">" ;
			tHtml += "<TR>" ;
				tHtml += "<TD STYLE=\"text-align: center; font-size: 8px\"><IMG src=\""+toolbarContent[0][i][0]+"\" WIDTH=\""+IMAGE_ICON_WIDTH+"px\" HEIGHT=\""+IMAGE_ICON_WIDTH+"px\" STYLE=\"border: 0px\" alt=\""+toolbarContent[0][i][1]+"\"></TD>" ;
			tHtml += "</TR>" ;
			tHtml += "</TABLE>" ;
		tHtml += "</TD>" ;		
	}
		tHtml += "<TD STYLE=\"text-align: center; font-size: 8px\">" ;
			tHtml += "<TABLE BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\" STYLE=\"FILTER: progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=20)\">" ;
			tHtml += "<TR>" ;
				tHtml += "<TD STYLE=\"text-align: center; font-size: 8px\"><IMG src=\"images/001.gif\" WIDTH=\""+IMAGE_ICON_WIDTH+"px\" HEIGHT=\""+IMAGE_ICON_WIDTH+"px\" STYLE=\"border: 0px\" onMouseOver=\"showToolbarMenu()\"></TD>" ;
			tHtml += "</TR>" ;
			tHtml += "</TABLE>" ;
		tHtml += "</TD>" ;
	tHtml += "</TR></TABLE>" ;

	tHtml += "<DIV ID=toolbarMenu STYLE=\"width: 250px; height: "+IMAGE_ICON_WIDTH+";background-color: #FFFFFF; color: #cccccc; position: absolute; border: 1px solid #8A0002; display: none; padding: 2px; cursor: hand; overflow: clip; FILTER: progid:DXImageTransform.Microsoft.Fade(Overlap=0.50)\">" ; //FILTER: progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=20)
		tHtml += "<TABLE WIDTH=\"250px\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\" onMouseOut=\"hiddenToolbarMenu()\">" ;
		for(i = 0 ; i < toolbarContent[1].length ; i++) {
			tHtml += "<TR><TD STYLE=\"font-size: 8px\">" ;
				tHtml += "<TABLE WIDTH=\"250px\" ID=tooObj"+i+" BORDER=\"0\" CELLSPACING=\"3\" CELLPADDING=\"0\" STYLE=\"FILTER: progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=20)\"  onMouseOver=\"whenMouseOverToolbarMenu(this)\" onMouseOut=\"whenMouseOut(this)\" onClick=\""+(toolbarContent[1][i][3].indexOf("call") >= 0 ? toolbarContent[1][i][3].substring(5) : "onMouseClickToolbar('"+toolbarContent[1][i][3]+"')")+"\">" ;
				tHtml += "<TR>" ;
					tHtml += "<TD WIDTH=\""+IMAGE_ICON_WIDTH+"px\" STYLE=\"font-size: 8px\"><IMG src=\""+toolbarContent[1][i][0]+"\" WIDTH=\""+IMAGE_ICON_WIDTH+"px\" HEIGHT=\""+IMAGE_ICON_WIDTH+"px\" STYLE=\"border: 0px\"></TD><TD STYLE=\"font-size: 8px; font-weight: bold\">"+toolbarContent[1][i][1]+"</TD>" ;
				tHtml += "</TR>" ;
				tHtml += "</TABLE>" ;
			tHtml += "</TD><TR>" ;		
		}
		tHtml += "</TABLE>" ;
	tHtml += "</DIV>" ;
	toolbar.innerHTML = tHtml ;
	
	toolbar.style.top = TOOLBAR_TOP ;
	toolbar.style.left = TOOLBAR_LEFT ;
	toolbarMenu.style.left	=	(toolbarPanel.children.length - 1) * (IMAGE_ICON_WIDTH+6) + 3; // 6 = 2 * CELLSPACING(3)
	toolbarMenu.style.top = 3 ; // CELLSPACING(3)
	whereGo.innerText = "top : " + toolbarz.style.width + "  children " + toolbarPanel.children.length ;
}

function showToolbarMenu() {
	if(toolbarMenuTimer != null)
		clearTimeout(toolbarMenuTimer) ;
	toolbarMenu.filters[0].apply() ;
	toolbarMenu.style.display = 'block' ;
	toolbarMenu.filters[0].play() ;
}

function hiddenToolbarMenu() {
	toolbarMenuTimer = setTimeout("toolbarMenu.style.display = 'none'", 180) ;
}

/*
	This function must has whenMouseOverToolbar(Object) function.
*/
function whenMouseOverToolbarMenu(obj) {
	if(toolbarMenuTimer != null)
		clearTimeout(toolbarMenuTimer) ;
	whenMouseOverToolbar(obj) ;
}

function whenMouseOverToolbar(obj) {
	clearTimeout(offMenuTimer) ;
	setText(toolbarContent[0][parseInt(obj.id.substring(6))][2]) ;
	currentMenu = obj ;

	if (currentMenu != oldMenu) {	// new menu is actived.
		if (oldMenu != null) {
			unFade(40) ;
		}
		oldMenu = currentMenu != null ? currentMenu : oldMenu ;		
	}
	doFade(currentMenu.filters("DXImageTransform.Microsoft.Alpha").Opacity) ;			
}

function onMouseClickToolbar(url) {
	whereGo.innerText = "From Toolbar : " + url ;
}

// alert('load complete') ;